Action.decoration = (function(){
    var targetImg = null,
        decoImgSelector = null;
    function init(){
        $("#toolBox>div>div:nth-of-type(4) img").click(addDeco);
    }

    function addDeco(event){
        targetImg = event.target;
        decoImgSelector = new Action.widget.Selector({
            customRender : addDecImg,
            afterResize : afterResize,
            imgsrc : event.target.src
        });
        $("#canvasBox>canvas").click(mergeImg);
    }
    function addDecImg(){
        $('<img src="'+this.config.imgsrc+'" width="'+this.width+'" height="'+this.height+'" border="none"/>').appendTo(this.contentDom);
    }

    function afterResize(){
        var img = $("img",this.contentDom)[0];
        img.width = this.width;
        img.height = this.height;
    }

    function mergeImg(){
        if(targetImg && decoImgSelector){
            PP.context.drawImage(targetImg,decoImgSelector.left,decoImgSelector.top,decoImgSelector.width,decoImgSelector.height);
            $(decoImgSelector.contentDom).parent().remove();
        }
    }

    return {
        init : init
    }
})();